<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="createLinkMan">创建</el-button>
			</div>
			<div class="left-panel"></div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="客户名称" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="linkManId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="客户名称" prop="cnName" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="姓名" prop="linkName" width="100" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="性别" prop="sex" width="100">
					<template #default="scope">
						<el-tag type="primary" size="small" v-if="scope.row.sex==='1'">男</el-tag>
						<el-tag type="danger" size="small" v-else-if="scope.row.sex==='0'">女</el-tag>
						<el-tag type="info" size="small" v-else>保密</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="决策人" prop="decisionMaker" width="100">
					<template #default="scope">
						<el-tag type="primary" size="small" v-if="scope.row.decisionMaker==='1'">是</el-tag>
						<el-tag type="danger" size="small" v-else-if="scope.row.decisionMaker==='0'">否</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="部门" prop="deptName" width="100"></el-table-column>
				<el-table-column label="职务" prop="post" width="100"></el-table-column>
				<el-table-column label="上级领导" prop="leadName" width="150"></el-table-column>
				<el-table-column label="移动电话" prop="mobile" width="150"></el-table-column>
				<el-table-column label="电子邮件" prop="email" width="200"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="170">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
</template>

<script>
import recordDetails from './details'
import saveDialog from './save'

export default {
	name: 'Crm Link Man Manage',
	components: {
		saveDialog,
		recordDetails
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave: false,
			},
			apiObj: this.$API.crm.crmLinkMan.getCrmLinkManAllList,
			search: {
				keyword: null
			}
		}
	},
	mounted() {
	},
	methods: {
		//添加
		createLinkMan() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		//删除
		async table_del(row) {
			var reqData = {linkManId: row.linkManId}
			var res = await this.$API.crm.crmLinkMan.deleteCrmLinkMan.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
